package org.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.example.entity.task.MyTask;
import org.example.mapper.MyTaskMapper;
import org.example.service.MyTaskService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 魏锴
 * @description 针对表【tb_task_mytask】的数据库操作Service实现
 * @createDate 2024-01-12 17:43:13
 */
@Slf4j
@Service
public class MyTaskServiceImpl extends ServiceImpl<MyTaskMapper, MyTask>
        implements MyTaskService {

    @Override
    public List<MyTask> getTaskList(int user_id) {
        return baseMapper.getTaskList(user_id);
    }

    @Override
    public boolean renewScan(int id) {
        return baseMapper.renewScan(id);
    }

    @Override
    public boolean renewMove(int id) {
        return baseMapper.renewMove(id);
    }

    @Override
    public boolean renewExploit(int id) {
        return baseMapper.renewExploit(id);
    }

    @Override
    public boolean acceptTask(int id) {
        if (baseMapper.getStatusById(id) != 0) return false;//非待接收状态
        return baseMapper.acceptTask(id);
    }

    @Override
    public boolean refuseTask(int id) {
        if (baseMapper.getStatusById(id) != 0) return false;//非待接收状态
        return baseMapper.refuseTask(id);
    }

    @Override
    public boolean finishTask(int id) {
        if (baseMapper.getStatusById(id) != 1) return false;//非接收状态
        return baseMapper.finishTask(id);
    }

    @Override
    public Map<Integer, String> getIdNameMap(int user_id) {
        List<Map<String, Object>> mapList = baseMapper.getIdNameMap(user_id);
        Map<Integer, String> result = new HashMap<>();
        for (Map<String, Object> map : mapList)
            result.put((Integer) map.get("id"), (String) map.get("name"));
        //提取myTaskId和TaskName的键值对
        log.info(mapList.toString());
        return result;
    }
}




